﻿using System.Collections;

namespace DelegateT1
{
    //? 代理类型本身继承自System.MulticastDelegate，具有广播特性，也就是一个传一个，而且重载了+=,-=
    public delegate void StringAssignmentEventHandler1();

    public class MulticastDelegateInvoker
    {
        private string[] message = new string[3];

        public MulticastDelegateInvoker()
        {
            StringAssignmentEventHandler1 handler1 = null;
            handler1 += new StringAssignmentEventHandler1(AppendHello);
            handler1 += new StringAssignmentEventHandler1(AppendComma);
            handler1 += new StringAssignmentEventHandler1(AppendWorld);
            handler1.Invoke();
        }

        public string this[int index]
        {
            get { return message[index]; }
        }

        public void AppendHello()
        {
            message[0] = "Hello";
        }

        public void AppendComma()
        {
            message[1] = ",";
        }

        public void AppendWorld()
        {
            message[2] = "World!";
        }
    }
}